package com.medicine.hbp.adapter;


import android.app.Activity;
import android.content.Intent;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.medicine.hbp.R;
import com.medicine.hbp.base.MyBaseAdapter;
import com.medicine.hbp.kankan.RoundProgressBar;
import com.medicine.hbp.mob.artGroupJyVo;
import com.medicine.hbp.ui.WebActivity;

import org.kymjs.kjframe.KJBitmap;
import org.kymjs.kjframe.widget.RoundImageView;

public class FragmentAdapter04 extends MyBaseAdapter {
	private KJBitmap bitmap = new KJBitmap();

	public FragmentAdapter04(Activity activity) {
		this.activity = activity;
	}

	@Override
	public View getView(int position, View view, ViewGroup arg2) {
		ViewHolder holder;
		if (view == null) {
			holder = new ViewHolder();
			view = LayoutInflater.from(activity).inflate(R.layout.item_classification_detail, arg2, false);
			holder.roundProgressBar3 = (RoundProgressBar) view.findViewById(R.id.roundProgressBar3);
			holder.img = (ImageView) view.findViewById(R.id.img);

			holder.title = (TextView) view.findViewById(R.id.title);
			holder.txt_num01 = (TextView) view.findViewById(R.id.txt_num01);
			holder.txt_num02 = (TextView) view.findViewById(R.id.txt_num02);
			holder.txt_num03 = (TextView) view.findViewById(R.id.txt_num03);
			holder.dis_username = (TextView) view
					.findViewById(R.id.dis_username);
			holder.dis_content = (TextView) view.findViewById(R.id.dis_content);
			holder.dis_hps = (TextView) view.findViewById(R.id.dis_hps);
			holder.layout_pl = (LinearLayout) view.findViewById(R.id.layout_pl);
			holder.img_userhead = (RoundImageView) view
					.findViewById(R.id.img_userhead);
			view.setTag(holder);
		} else {
			holder = (ViewHolder) view.getTag();
		}
		final artGroupJyVo Vo = (artGroupJyVo) getItem(position);
		if (Vo != null) {
			holder.title.setText(Vo.artTitle);
			if(Vo.artPraiseRate==-1){//��ֵΪ-1ʱԲȦ����
				holder.roundProgressBar3.setVisibility(View.GONE);
			}else{
				holder.roundProgressBar3.setVisibility(View.VISIBLE);
				holder.roundProgressBar3.setProgress(Vo.artPraiseRate);
			}
			holder.txt_num01.setText(String.valueOf(Vo.artDiscussNumber));
			holder.txt_num02.setText(String.valueOf(Vo.artPraiseNumber));
			holder.txt_num03.setText(String.valueOf(Vo.artCollectNumber));
			if (Vo.artImg.size() > 0) {
				bitmap.display(holder.img, Vo.artImg.get(0).artImgUrl);
			}else{
				holder.img.setImageResource(R.mipmap.imgceshi2);
			}
//			if (!TextUtils.isEmpty(Vo.artImg)) {
//				bitmap.display(holder.img, Vo.artImg);
//			}else{
//				holder.img.setImageResource(R.drawable.imgceshi2);
//			}
			if (TextUtils.isEmpty(Vo.discussNote)) {
				holder.layout_pl.setVisibility(View.GONE);
			} else {
				holder.layout_pl.setVisibility(View.VISIBLE);
				bitmap.display(holder.img_userhead, TextUtils.isEmpty(Vo.discussUser.userHeadImg)?"":Vo.discussUser.userHeadImg);
				holder.dis_username.setText(String
						.valueOf(Vo.discussUser.userName));
				holder.dis_content.setText(String.valueOf(Vo.discussNote));
				holder.dis_hps.setText(String.valueOf(Vo.discussPraiseNumber));
			}
			view.setOnClickListener(new OnClickListener() {
				@Override
				public void onClick(View arg0) {
					Intent intent = new Intent(activity, WebActivity.class);
					intent.putExtra("ID", Vo.artId);
					intent.putExtra("vo", Vo);
					intent.putExtra("NAME", "������������");
					intent.putExtra("isCollect", Vo.isCollect);
					activity.startActivity(intent);

				}
			});
		}
		return view;
	}

	class ViewHolder {
		ImageView img;
		RoundProgressBar roundProgressBar3;
		TextView title;
		TextView txt_num01;
		TextView txt_num02;
		TextView txt_num03;

		TextView dis_username;
		TextView dis_content;
		TextView dis_hps;
		LinearLayout layout_pl;
		RoundImageView img_userhead;
	}
}
